package com.net.shop.car.manager;

import java.util.ArrayList;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import android.widget.TextView;

public class MenuActivity extends BaseActivity {
	private LinearLayout atm_detail_ll;
	private TableLayout menu_table;
	private ArrayList<String> dic_name;
	private Dialog dialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_menu);
		initView();
		initData();
	}

	public void initView() {
		// TODO Auto-generated method stub
		atm_detail_ll = (LinearLayout) findViewById(R.id.atm_detail_ll);
		menu_table = (TableLayout) findViewById(R.id.menu_table);
	}

	public void initData() {
		// TODO Auto-generated method stub
	}

	private void drawTablayout(int slSize) throws Exception {
		// TODO Auto-generated method stub
		// TableLayout table = (TableLayout) getLayoutInflater().inflate(
		// R.layout.tablelayout, null);
		menu_table.removeAllViews();
		if (slSize == 0) {
			return;
		}
		int lineSize = slSize / 3;
		if (slSize % 3 != 0) {
			lineSize++;
		}
		if (slSize < 3) {
			TableRow tr = new TableRow(this);
			tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
			tr.setPadding(1, 1, 1, 1);
			tr.setBackgroundResource(R.color.gray_c);
			for (int i = 0; i < slSize; i++) {
				final TextView nameText = (TextView) getLayoutInflater().inflate(R.layout.textview2, null);
				nameText.setText(dic_name.get(i));
				// nameText.setText(16);
				nameText.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						Intent intent = new Intent();
						intent.putExtra("str_result", nameText.getText().toString());
						intent.setClass(MenuActivity.this, MapActivity.class);
						setResult(0, intent);
						finish();
					}
				});
				tr.addView(nameText);
			}
			menu_table.addView(tr);
		} else {
			for (int s = 0; s < lineSize; s++) {
				final int po = s;
				TableRow tr = new TableRow(this);
				tr.setBackgroundResource(R.color.gray_c);
				tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
				tr.setPadding(1, 1, 1, 1);
				for (int i = 0; i < 3; i++) {
					final TextView nameText = (TextView) getLayoutInflater().inflate(R.layout.textview2, null);
					if (s * 3 + i < slSize) {
						nameText.setText(dic_name.get(s * 3 + i));
						nameText.setBackgroundResource(R.color.common_white);
						// nameText.setText(16);
						nameText.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View arg0) {
								// TODO Auto-generated method stub
								Intent intent = new Intent();
								intent.putExtra("str_result", nameText.getText().toString());
								intent.setClass(MenuActivity.this, MapActivity.class);
								setResult(4, intent);
								finish();
							}
						});
					} else {
						nameText.setText("");
						nameText.setBackgroundResource(R.color.common_white);
					}

					tr.addView(nameText);

				}
				menu_table.addView(tr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

			}
		}

	}

}
